@extends('admin.layout.homeindex')
@section('content')
<div id="page-content" class="single-page">
	<div class="container">
		<div class="row">
			<div class="col-lg-12">
				<ul class="breadcrumb">
					<li><a href="{{url('/')}}">首页</a></li>
					<li><a href="cart.html">购物车</a></li>
				</ul>
			</div>
		</div>
		@foreach($carts as $k=>$v)
		<div class="row" sid="{{$v->id}}">
			<div class="product well">
				<div class="col-md-3">
					<div class="image">
						<img src="{{$v->pic}}" />
					</div>
				</div>
				<div class="col-md-9">
					<div class="caption">
						<div class="name"><h3><a href="product.html">{{$v->title}}</a></h3></div>
						<div class="price">
						单价：{{$v->price}}
						</div>
						<label>数量: </label> 
						<button id="goods_d" type="button" class="goods_d btn btn-default"> - </button>
						<input id="goods_num" type="text" value="{{$v->num}}" style="width:40px">
						<button id="goods_a" type="button" class="goods_a btn btn-default"> + </button>
						<div class="price">小计：{{$v->price * $v->num}}</div>
						<hr>
						<a class="sc btn btn-default pull-right">删除</a>
					</div>
				</div>
				<div class="clear"></div>
			</div>	
		</div>
		@endforeach
		<div class="row">
			<div class="col-md-4 col-md-offset-8 ">
				<center><a href="" class="btn btn-1">继续购物</a></center>
			</div>
		</div>
		<div class="row">
			<div class="pricedetails">
				<div class="col-md-4 col-md-offset-8">
					<table>
						<h6>价格详情</h6>
						<tr>
							<td>原价</td>
							<td>350.00</td>
						</tr>
						
						<tr>
							<td>邮费</td>
							<td>100.00</td>
						</tr>
						<tr style="border-top: 1px solid 333">
							<td><h5>总价</h5></td>
							<td>400.00</td>
						</tr>
					</table>
					<center><a href="" class="btn btn-1">提交订单</a></center>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$('.goods_d').click(function(){
		//获取商品数量 转成int
		var num = parseInt($('#goods_num').val());
		//计算
		num = num - 1;
		//判断最小值为1
		if(num == 0) return;
		//更新赋值
		$('#goods_num').val(num);
		});
	$('.goods_a').click(function(){
		//获取商品数量
		var num = parseInt($('#goods_num').val());
		//计算
		num = num + 1;
		//更新赋值
		$('#goods_num').val(num);
	});

	//删除 绑定单击时间
	$('.sc').click(function(){
		//获取ID
		var id = $(this).parents('.row').attr('sid');
		var td = $(this);
		//发送ajax
		$.get('/cart/delete',{id:id},function(data){
			if(data == 1){
				td.parents('.row').remove();
			};
		});
	});
	
</script>
@endsection('content')